﻿using System;
using System.Collections;
using Microsoft.ReportingServices.DataProcessing;
using System.Management.Automation;

namespace PowerShellDataProcessingExtension
{
    /// <summary>
    /// Represents a collection of all parameters relevant to a command or query.
    /// </summary>
    /// <remarks>
    /// The IDataParameterCollection interface enables you to implement a parameter collection.
    /// An application does not create an instance of the IDataParameterCollection interface directly, 
    /// but creates an instance of a class that implements IDataParameterCollection.
    /// Classes that implement IDataParameterCollection must implement the required members, 
    /// and typically define additional members to add provider-specific functionality.
    /// The Reporting Services IDataParameterCollection interface inherits from IEnumerable and requires that you implement an Add method. 
    /// IEnumerable also requires that you implement a GetEnumerator method. 
    /// Because IDataParameterCollection is a type of IList, you can use an existing class for most of the implementation. 
    /// For example, if your DataParameter class inherits ArrayList, you can use the default implementation of the ArrayList.GetEnumerator method.
    /// </remarks>
    class PSDataParameterCollection : ArrayList,IDataParameterCollection
    {
      
        /// <summary>
        /// Adds an IDataParameter to the collection
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public override int Add(Object value)
        {
            return Add((IDataParameter)value);
        }

        /// <summary>
        /// Adds an IDataParameter to the collection
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        int IDataParameterCollection.Add(IDataParameter parameter)
        {
            if (parameter.ParameterName != null)
            {
                return base.Add(parameter);
            }
            else
            {
                throw new ArgumentException("parameter must be named");
            }
        }

        public Object this[String index]
        {
            get
            {
                return this[IndexOf(index)];
            }
            set
            {
                this[IndexOf(index)] = value;
            }
        }

    }
}
